/*
 * Jiri Cigler
 * ciglej1@fel.cvut.cz 
 *
 * Copyright (C) 2007 Jirka Cigler <ciglej1@fel.cvut.cz>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 */ 


#ifndef __SCHEDULER_HH__
#define __SCHEDULER_HH__

#include <iostream>
#include <iomanip>

#include <cstdlib>
#include <cstring>

#include "gecode/kernel.hh"
#include "gecode/int.hh"
#include "gecode/search.hh"
#include "gecode/minimodel.hh"
#include <vector> 
#include <string>

#include "../src/timer.hh"
#include "../src/types.hh"

using namespace Gecode;

void run(int **& resource, unsigned int **& duration, const int jobs, int tasksInJob, int machines, unsigned int **& result,double * runtime); 

extern std::vector<Activity> listOfActivities;
extern std::vector<SortTableElement> sortTable;

class Scheduler :  public Space {

	protected:
		static unsigned int copies;

		unsigned int copy_nr;

		int jobs, tasksInJob, machines;

		IntVarArray q;
	public:

		Scheduler(  int jobs, int tasksInJob, int machines, unsigned int maxTime);
		~Scheduler();
		Scheduler(bool share, Scheduler& iScheduler) : Space(share,iScheduler) {
			copy_nr = ++copies; 
			q.update(this, share, iScheduler.q);
			jobs = iScheduler.jobs;
			tasksInJob= iScheduler.tasksInJob;
			machines= iScheduler.machines;
		}

		void result(unsigned int ** & r);

		void print(void);

		Space*  copy(bool share) {return new Scheduler(share,*this); }

		void constrain(Scheduler* iScheduler);

	private:
		explicit Scheduler(Scheduler& iScheduler);

		void solve();
};

#include "scheduler.icc"

#endif

